package com.codejiwei.flink.practice;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author jiwei
 * @description 对两个或者两个以上的DataStream进行union操作，产生一个包含所有DataStream元素的新DataStream
 *
 * 1.union之前两个流的类型必须是一样，connect可以不一样
 * 2.connect只能操作两个流，union可以操作多个。
 * @date 2023/5/19 17:27
 */
public class Flink_Transform_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);

        DataStreamSource<Integer> stream1 = env.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<Integer> stream2 = env.fromElements(10, 20, 30, 40, 50);
        DataStreamSource<Integer> stream3 = env.fromElements(100, 200, 300, 400, 500);

        stream1.union(stream2)
                .union(stream3)
                .print();

        env.execute();

    }
}
